package com.demo.controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.demo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.sql.DataSource;
import java.util.*;

/**
 * @ClassName HelloWord
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/8 11:05
 * @Version 1.0
 **/
@Controller
public class HelloWorld {
    @RequestMapping("/hello")
    @ResponseBody
    public Map<String, Object> showHelloWorld() {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "HelloWorld");
        return map;
    }

//    @Autowired
//    DruidDataSource dataSource;
//    @RequestMapping("/dataSource")
//    @ResponseBody
//    public Map<String, Object> showDataSource() {
//        Map<String, Object> map = new HashMap<>();
//        map.put("url", dataSource.getUrl());
//        map.put("driver",dataSource.getDriverClassName());
//        return map;
//    }

    @RequestMapping("/userMessage")
    public String showUser(Model model) {
        List<User> users=new ArrayList<>();
        for (int i=0;i<10;i++) {
            User user = new User("张三" + i,( i % 2 == 1 ? "男" : "女"), new Date());
            users.add(user);
        }
        System.out.println(users);
        model.addAttribute("msg","sssssssss");
        model.addAttribute("users",users);

        return "showUser";
    }

    @RequestMapping("/resultsMap")
    @ResponseBody
    public String requestMap(String id ,String name){
        return id+" "+name;
    }

    @RequestMapping("/resultsMap2/{id}/{name}")
    @ResponseBody
    public String requestMap2(@PathVariable  String id , @PathVariable String name){
        return id+" "+name;
    }

    @RequestMapping("/resultsMap1/{id}")
    @ResponseBody
    public String requestMap1(@PathVariable String id ,String name){
        return id+" "+name;
    }

//    @RequestMapping("/hello")
//    public String showHelloWorld() {
//       return "demo";
//    }
}